package com.aaa.mrcai.util;



import com.aaa.mrcai.pojo.entity.Permission;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author:Li-Yan-Chun
 * @Date:2021/11/26 20:25
 */
public class PermissionUtil {
    public static List<Permission> handlePermission(List<Permission> commentPers){
        /*commentPers[{m},{c},{c},{m},{c},{c},]*/
        List<Permission> haha = new ArrayList<>();
        for (Permission commentPer : commentPers) {
            String type = commentPer.getType();
            if ("M".equals(type)){
                //haha中加入一级菜单
                haha.add(commentPer);
            }
        }
        for (Permission commentPer : commentPers) {
            String type = commentPer.getType();
            if (!"M".equals(type)){//二级菜单
                for (Permission permission : haha) {
                    Integer id1 = permission.getId();
                    //二级菜单的pid和一级菜单的id相同
                    if (id1.equals(commentPer.getPid())){
                        //将二级菜单加入到相应的一级菜单中
                        permission.getSubMenu().add(commentPer);
                    }
                }
            }
        }
        return haha;
    }
}
